// 统计与日志通用接口
import uuid from 'uuid'
import AuthInfo from '@/utils/auth/info.js'
import {http} from '@/utils/request/http.js';

let device_uid = AuthInfo.getUuid();
// console.log(typeof(device_uid), device_uid === '')
if(typeof(device_uid) === "undefined" || device_uid === '') {
    device_uid = uuid.v4();
    AuthInfo.setUuid(device_uid)
}
console.log("device_uid:", device_uid);
const getPageRoute = function() {
    let pages = getCurrentPages();
    return pages[pages.length - 1].route;
}
const appOnShowLog = function() {
    // try {uni.setStorageSync(userKey, user);return true;} catch (e) {return false;}
    let reqData = {device_uid: device_uid, type: 'app_on_show'}
    http.post('/statistic', reqData).then(res =>{
        console.log(res);
    })
}

const pageOnLoadLog = function() {
    
    let route = getPageRoute();
    let reqData = {device_uid: device_uid, page_route: route};
    // console.log(reqData);return;
    http.post('/statistic', reqData).then( res => {
        console.log(res)
    })
}

export default {
    appOnShowLog, pageOnLoadLog,
}

// export const v1 = uuid.v1;
// export const v3 = uuid.v3;
// export const v4 = uuid.v4;
// export const v5 = uuid.v5;
// export const NIL = uuid.NIL;
// export const version = uuid.version;
// export const validate = uuid.validate;
// export const stringify = uuid.stringify;
// export const parse = uuid.parse;